home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _81883F688FDF4DF484484E7B1770E306 < prev    next >
Text File  |  2004-11-27  |  2KB  |  62 lines

  1. ///campfire particle shader
  2. //input should be 4 points that are the same position
  3. //color0 (diffuse) used normally
  4. //color1 (spec): green,red are tex coord, blue = size modifier
  5. //Luke Lenhart
  6. //(C)2004-2005 Digipen Institute of Technology
  7.  
  8. //world,view,projection transform
  9. float4x4 matWorldViewProj;
  10.  
  11. //camera position in world space
  12. float4 cameraPos;
  13.  
  14. //particle size modifier
  15. float size;
  16.  
  17. //base position of emitter
  18. float3 basePos;
  19.  
  20. //shader input
  21. struct VS_INPUT
  22. {
  23.     float4 Pos : POSITION;
  24.     float4 Color : COLOR0;
  25.     float4 Spec : COLOR1;
  26. };
  27.  
  28. //shader output
  29. struct VS_OUTPUT
  30. {
  31.     float4 Pos : POSITION;
  32.     float4 Color : COLOR;
  33.     float2 Tex0 : TEXCOORD0;
  34. };
  35.  
  36. //shader code
  37. VS_OUTPUT VShader(VS_INPUT In)
  38. {
  39.     VS_OUTPUT Out;
  40.     
  41.     //transform pos and copy tex coord and color over
  42.     Out.Pos=mul(matWorldViewProj,In.Pos);
  43.     Out.Tex0=In.Spec.xy;
  44.     Out.Color=In.Color;
  45.     
  46.     //expand outwards from center point, based on distance and tex coord
  47.     float distmod=0.08f + 1.0f / pow(distance(cameraPos,In.Pos),0.5f);
  48.     float2 posOffset=In.Spec.xy - float2(0.5f,0.5f);
  49.     float sizeMod=(0.5f + In.Spec.z*2.0f);
  50.     
  51.     //calc rotation matrix based on in component
  52.     float theta=dot(In.Pos,float3(0.2f,0.2f,0.2f))+(1.0f / pow(In.Pos.z-basePos.z, 1.5f))*8.0f;
  53.     float2x2 matRot={cos(theta),sin(theta),-sin(theta),cos(theta)};
  54.     posOffset=mul(matRot,posOffset);
  55.     
  56.     //app offset to output position
  57.     Out.Pos.xy+=posOffset*distmod*size*sizeMod;
  58.  
  59.     //spit out the results
  60.     return Out;
  61. }
  62.